package com.jason.demo;

import java.sql.*;

public class jdbcDemo {
    // 连接信息
    private final String driver = "oracle.jdbc.driver.OracleDriver";
    private final String url = "jdbc:oracle:thin:@192.168.43.128:1521:orcl";
    private final String user = "scott";
    private final String password ="tiger";

    /**
     * 访问Oracle数据库
     */
    @org.testng.annotations.Test
    public void testOracle() {
        // TODO 1. 加载驱动
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            // TODO 2. 获取连接
            conn = DriverManager.getConnection(url, user, password);
            // TODO 3. 执行sql
            ps = conn.prepareStatement("select * from emp");
            // TODO 4. 获得结果集
            rs = ps.executeQuery();
            while (rs.next()) {
                System.out.println(rs.getInt("EMPNO") + "," + rs.getString("ENAME"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /*
     * Oracle存储过程
     */
    public void sqlProcedureTest() {

    }
}
